package com.djinfo.work.controller;

import com.djinfo.work.common.bean.AjaxJson;
import com.djinfo.work.common.util.StringUtil;
import com.djinfo.work.entity.QsContentEntity;
import com.djinfo.work.entity.QsTitleEntity;
import com.djinfo.work.service.QsContentService;
import com.djinfo.work.service.QsTitleService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

/**
 * Created by admin on 2017/6/13.
 */
@Controller
@RequestMapping("/QsContent")
public class QsContentController {
    private static final Log log = LogFactory.getLog(QsTitleController.class);

    @Autowired
    private QsContentService qsContentService;
    @Autowired
    private QsTitleService qsTitleService;


    /**
     * 问卷内容列表
     */
    @RequestMapping("/list.do")
    @ResponseBody
    public AjaxJson list(QsContentEntity qsContentEntity, Integer pagenum, Integer pagesize){
        AjaxJson ajaxJson=qsContentService.list(qsContentEntity,pagenum,pagesize);
        return ajaxJson;
    }
    /**
     * 新增修改操作
     */
    @RequestMapping("/saveOrUpdate.do")
    @ResponseBody
    public AjaxJson addOrUpdate(QsContentEntity qsContentEntity, HttpServletRequest request){
        AjaxJson ajaxJson=qsContentService.saveOrUpdate(qsContentEntity,request);
        return ajaxJson;
    }

    /**
     * 获取标题对象信息
     */
    @RequestMapping("/info.do")
    public ModelAndView info(QsContentEntity qsContentEntity){
        if(qsContentEntity.getId()==null||"".equals(qsContentEntity.getId())){
            qsContentEntity=new QsContentEntity();
        }else {
            qsContentEntity = qsContentService.getById(qsContentEntity.getId());
            QsTitleEntity qsTitleEntity=qsTitleService.getQsTitleById(qsContentEntity.getTitleId());
            if(qsTitleEntity!=null){
                qsContentEntity.setTitleName(qsTitleEntity.getTitleName());
            }
        }
        return new ModelAndView("qs_content/edit.html","content",qsContentEntity);
    }
    @RequestMapping("/delete.do")
    @ResponseBody
    public AjaxJson delete(String id){
        AjaxJson ajaxJson=qsContentService.delete(id);
        return ajaxJson;
    }









}
